#ifndef CLIENTHANDLE_H
    #define CLIENTHANDLE_H

#pragma once
#include <QObject>
#include <QByteArray>
#include <QDebug>
#include <QTcpSocket>
#include <QVariant>
// #include <QTcpServer>


struct ClientInfo
{
    QHostAddress    client_ip;          // 客户端地址
    quint16         client_port;        // 客户端端口
    QString         current_message;    // 客户端发来的消息
};
Q_DECLARE_METATYPE(ClientInfo)  // 通过Q_DECLARE_METATYPE声明后，就可以让自定义的类型设置到QVariant。

class ClientHandle : public QObject
{
    Q_OBJECT

public:
    explicit ClientHandle(QObject* parent = nullptr);
    explicit ClientHandle(qintptr socketDescriptor, QObject* parent = nullptr);
    ~ClientHandle();

    // 发送消息函数
    // qint64 send_message_slot();

    // 获得私有成员函数
    QTcpSocket* get_client_socket();
    const ClientInfo* get_client_info();


protected:

private slots:
    void recv_info_slot();
    void disconnect_slot();

public slots:
    void working();

signals:
    void send_message_to_server_signal(const ClientInfo* clint_info);

    void disconnect_signal(ClientHandle* self);

private:
    QTcpSocket*     client_socket;
    qintptr         client_socketDescriptor = 0;

    // 连接信息
    ClientInfo*     client_info;    // 通过 QVariant 储存 ClientHandle
};

#endif // CLIENT_HANDLE_H
